#ifndef MOCHA_DETAIL_IMPORTED_OBJECT_HPP_INCLUDED
#define MOCHA_DETAIL_IMPORTED_OBJECT_HPP_INCLUDED

/**
 * @file
 */

#include "mocha/plugin.hpp"

namespace mocha {
/**
 * Base for imported (adapted) objects.
 * Provides simple access to and automatic deletion of the underlying foreign object.
 * Implements the imported concept.
 * @param T Foreign object type.
 */
template<typename T>
class imported_object {
public:
	typedef T unadapted_type;
	imported_object(T* object, mocha_plugin_destroy_func_t destroy): object_(object), destroy_(destroy) {
		if (!object_) { /*...*/ }
	}
	virtual ~imported_object() {
		if (destroy_) {
			destroy_(object_);
		}
	}
protected:
	/**
	 * @return Underlying unadapted object.
	 */
	T* unadapted() {
		return object_;
	}
	/**
	 * @return Underlying unadapted object.
	 */
	const T* unadapted() const {
		return object_;
	}
private:
	T* object_;
	mocha_plugin_destroy_func_t destroy_;
};
}

#endif

